PHP Core / Date / Month Difference
Month Difference
-
Code
public function monthDiff($date1, $date2){ $date1 = new \DateTime($date1); $date2 = new \DateTime($date2); $interval = $date1->diff($date2); $months = ($interval->y * 12) + $interval->m; return $months+1; } $inputData['quantity']= $this->monthDiff( " 2020-12-01", "2023-12-01");